//
//  ViewController.swift
//  JRSLive
//
//  Created by orvibo on 2017/10/20.
//  Copyright © 2017年 Alic. All rights reserved.
//

import UIKit
import WebKit

class ViewController: UIViewController,WKUIDelegate,WKNavigationDelegate {
    
    var baseUrl = "http://nba.tmiaoo.com" // 也不错
    var baseUrl3 = "http://a.tmiaoo.com/ipad.html"
    var baseUrl5 = "http://m.kanbisai.tv" // 很好无广告
    
    var candidateUrl = "http://www.jrstv.cc/#nba" // 有广告
    
    var baseUrl1 = "https://www.baidu.com"
    var baseUrl2 = "http://a.tmiaoo.com/iphone.html"
    var baseUrl4 = "http://nba.tmiaoo.com/po/4w.php"
    
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        let webView = WKWebView.init(frame: self.view.bounds)
        webView.uiDelegate = self
        webView.navigationDelegate = self
        
        self.view.addSubview(webView)
        
        webView.load(URLRequest.init(url: NSURL.init(string: baseUrl5)! as URL))
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    
    
    public func webViewDidClose(_ webView: WKWebView){
        
        print(1)
    }
    
    public func webView(_ webView: WKWebView, commitPreviewingViewController previewingViewController: UIViewController)

    {
        print(2)

    }
    
 
    public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Swift.Void)
    {
        decisionHandler(.allow)
        print(3)

    }
    

    public func webView(_ webView: WKWebView, decidePolicyFor navigationResponse: WKNavigationResponse, decisionHandler: @escaping (WKNavigationResponsePolicy) -> Swift.Void)
    {
        decisionHandler(.allow)
        print(4)

    }
    
    public func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!)
    {
        print(5,webView.url!)
    }
    

    public func webView(_ webView: WKWebView, didReceiveServerRedirectForProvisionalNavigation navigation: WKNavigation!)
    {
        print(6)

    }

    public func webView(_ webView: WKWebView, didFailProvisionalNavigation navigation: WKNavigation!, withError error: Error)
    {
        print(7)

    }
    

    public func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!)
    {
        print(8)

    }

    public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!)
    {
        print(9,webView.url!)

    }
    
    public func webView(_ webView: WKWebView, didFail navigation: WKNavigation!, withError error: Error)
    {
        print(10)

    }

    
    public func webView(_ webView: WKWebView, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Swift.Void)
    {
        completionHandler(.performDefaultHandling,URLCredential.init())
        print(11)

    }
    
    public func webViewWebContentProcessDidTerminate(_ webView: WKWebView)
    {
        print(12)

    }
    
}

